package com.tony.schedule;

import java.math.BigDecimal;
import java.util.Random;

import org.apache.log4j.Logger;

import com.tony.dao.AccountDAO;
import com.tony.dataobject.AccountDO;
import com.tony.util.DateUtil;
import com.tony.util.LoggerUtil;

/**
 * 每分钟增加100个账号
 * 
 * @author hai.yuan
 * @version $Id: DepositScheduler.java, v 0.1 2013-6-2 上午4:43:22 hai.yuan Exp $
 */
public class RegistScheduler {

    private AccountDAO         accountDAO;

    public static final Random random = new Random();

    public static final Logger logger = Logger.getLogger("scheduler.log");

    public void registAccount() {

        long start = System.currentTimeMillis();

        LoggerUtil.info(logger, "开始定时注册了,TimeKey=" + start);

        for (int j = 0; j < 10; j++) {
            for (int i = 0; i < 10; i++) {

                try {

                    AccountDO accountDO = new AccountDO();

                    accountDO.setEmail(DateUtil.getTodayString() + random.nextInt(10) + ""
                                       + random.nextInt(10) + "" + random.nextInt(10) + ""
                                       + random.nextInt(10));
                    accountDO.setBalance(new BigDecimal(DateUtil.getDateLongString() + i + "" + j));

                    accountDAO.insert(accountDO);
                } catch (Exception e) {
                    LoggerUtil.error(logger, "定时注册失败,TimeKey=" + start, e);
                }
            }
        }

        LoggerUtil.info(logger, "定时注册完毕，耗时：" + (System.currentTimeMillis() - start) + "ms,TimeKey="
                                + start);

    }

    /**
     * Setter method for property <tt>accountDAO</tt>.
     * 
     * @param accountDAO value to be assigned to property accountDAO
     */
    public void setAccountDAO(AccountDAO accountDAO) {
        this.accountDAO = accountDAO;
    }

}
